package com.zzptc.myapp1023;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ListView listView;
    List<Student> list_stu=new ArrayList<>();
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        for (int i = 0; i < 100; i++) {
            Student student = new Student(R.mipmap.ic_launcher, i, "姓名" + i, new Date() + "");
            list_stu.add(student);
        }
        for (Student s : list_stu) {
            Log.d(TAG, s.getName());

        }
//适配器
        MyAdapter myAdapter=new MyAdapter();
        listView.setAdapter(myAdapter);

    }

    class MyAdapter extends BaseAdapter {


        @Override
        public int getCount() {
            return list_stu.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            //
            Student student = list_stu.get(position);
            //
            View View1 = View.inflate(MainActivity.this, R.layout.item_stu, null);
            //
            ImageView iv_pic = View1.findViewById(R.id.iv_pic);
            iv_pic.setImageResource(R.mipmap.ic_launcher);
            TextView tv_id = View1.findViewById(R.id.tv_id);
            tv_id.setText(student.getId() + "");//
            TextView tv_name = View1.findViewById(R.id.tv_id);
            tv_name.setText(student.getName());
            TextView tv_date = View1.findViewById(R.id.tv_date);
            tv_date.setText(student.getTime());


            return View1;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.myoption,menu);

        //menu.add(0,1,1,"关于");
        //menu.add(0,2,2,"账号");

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
       // Toast.makeText(this, "你点击关于"+item.getItemId(), Toast.LENGTH_SHORT).show();

        return true;
    }

}



